package com.lc.user.express.httpserver;

import com.lc.user.express.model.MyIntegralModel;
import com.zcx.helper.http.AsyCallBack;
import com.zcx.helper.http.note.HttpInlet;

import org.json.JSONArray;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by Administrator on 2016/3/30.我的积分
 */
@HttpInlet(Net.GET_INTEGRAL)
public class GetMyIntegral extends ZJDBAsyGet<GetMyIntegral.Info> {
    public String userid;

    public GetMyIntegral(String userid, AsyCallBack asyCallBack) {
        super(asyCallBack);
        this.userid = userid;
    }

    @Override
    protected Info parser(JSONObject object) {
        if (object.optInt("message") == 1) {
            Info info = new Info();
            info.number = object.optInt("number");
            info.money=object.optInt("money");
            info.integral=object.optInt("integral");
            JSONArray array = object.optJSONArray("list");
            if (array != null) {
                for (int i = 0; i < array.length(); i++) {
                    JSONObject object1 = array.optJSONObject(i);
                    MyIntegralModel myIntegralModel = new MyIntegralModel();
                    myIntegralModel.setId(object1.optString("id"));
                    myIntegralModel.setMoney(object1.optString("money"));
                    myIntegralModel.setIntegral(object1.optString("integral") + "积分兑换");
                    myIntegralModel.setStarttime(object1.optString("startime"));
                    myIntegralModel.setEndtime(object1.optString("endtime"));
                    info.datalist.add(myIntegralModel);
                }
                return info;
            }
        }
        return null;
    }

    public static class Info {
        public int number;
        public List<MyIntegralModel> datalist = new ArrayList<>();
        public int money;
        public int integral;
    }
}
